#pragma once

#include <windows.h>
#include <d3dx9math.h>

#include "Vector3.h"
#include "Quaternion.h"

class Matrix : public D3DXMATRIX
{
public:
	Matrix(void);
	Matrix(float m11, float m12, float m13, float m14,
		float m21, float m22, float m23, float m24,
		float m31, float m32, float m33, float m34,
		float m41, float m42, float m43, float m44 );
	Matrix( const D3DXMATRIX & matrix );
	Matrix( const Quaternion & quaternion );
	Matrix( const Vector3 & position, const Quaternion & quaternion );
	Matrix( const Vector3 & position, const Vector3 & ypr );

	~Matrix(void);

public:
	void MakeTransform( const Vector3 & pos, const Vector3 & ypr ); 

	void MakeScaling( const float x, const float y, const float z );
	
	void MakeTranslation( const float x, const float y, const float z );
	void MakeTranslation( const Vector3 & pos );

	void MakeRotationX( const float radian );
	void MakeRotationY( const float radian );
	void MakeRotationZ( const float radian );
	void MakeRotation( const float y, const float p, const float r );
	void MakeRotation( const Vector3 & ypr );
	void MakeRotation( const Quaternion & quat );
	void MakeRotationFromDirection( const Vector3 & direction, const Vector3 & up );

	void TransformCoord( Vector3 & result, const Vector3 & vector );
	void TransformNormal( Vector3 & result, const Vector3 & normal );

	BOOL GetInverse( Matrix & result );
	BOOL GetInverseTransporse( Matrix & result );
	void GetTranspose( Matrix & result );

	void SetTranslation( const Vector3 & pos );
	Vector3 GetTranslation();

	Vector3 GetScale();

	float GetYaw();
	float GetPitch();
	float GetRoll();
	Vector3 GetYawPitchRoll();

	void PreMultiply( const Matrix & other );
	void PostMultiply( const Matrix & other );

	void Identity() { D3DXMatrixIdentity( this ); }

	static const Matrix IDENTITY;
};
